﻿<%@ Assembly Name="PeopleEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e7d0207ddf77cee" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PeopleEditor.aspx.cs" Inherits="PeopleEditor.Layouts.PeopleEditor.PeopleEditor" DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <table>
            <tr>
                    <td> Select User </td>
                    <td>
                         <SharePoint:PeopleEditor runat="server" ID="PeopleEditor_SingleUser" AllowTypeIn="True"
                                MultiSelect="False" AllowEmpty="False"
                                 CssClass="span8" SelectionSet="User,SecGroup,SPGroup" PlaceButtonsUnderEntityEditor="False"
                                 BrowseButtonImageName="/_layouts/inceimages/24/find.png"
                                 CheckButtonImageName="/_layouts/inceimages/24/submit.png"
                                 
                             />

                    </td>
            </tr>
			 <tr>
                    <td colspan="2"> 
                      <input type="text" value="" id="txt_singleUser" class=span8 /> 
                     <input type="button" onclick="getDataSingleUSer1()" value="Get Value of Single User" id="GetValueOfSingleUser" />  </td>
            </tr>
            <tr>
                    <td> Select Multi-User </td>
                    <td>
                         <SharePoint:PeopleEditor runat="server" ID="PeopleEditor_multiUser" AllowTypeIn="True"
                                MultiSelect="true" AllowEmpty="False"
                                 CssClass="span8" SelectionSet="User,SecGroup,SPGroup" PlaceButtonsUnderEntityEditor="False"
                                 BrowseButtonImageName="/_layouts/inceimages/24/find.png"
                                 CheckButtonImageName="/_layouts/inceimages/24/submit.png"
                                 
                             />

                    </td>
            </tr>
			 <tr>
                    <td colspan="2"> 
                      <input type="text" value="" id="txt_MultiUser" class=span8 style="width:600px" /> 
                     <input type="button" onclick="getDataMultiUSer()" value="Get Value of multi User" id="Button1" />  </td>
            </tr>

    </table>
    <script>
        var FieldName_singleUser = "<%=PeopleEditor_SingleUser.ClientID%>_upLevelDiv";
        var FieldName_MultiUser = "<%=PeopleEditor_multiUser.ClientID%>_upLevelDiv";

        var _multi_user_array = new Array();
        var _multi_user_array_Index = 0;

        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        var DOMAIN_NAME = "YOUR_DOMAIN_NAME";
        var Search_text = "title=" + DOMAIN_NAME;


        function getDataSingleUSer1() {

            var i = 0;
            var j = 0;
            var s = document.getElementById(FieldName_singleUser).innerHTML;

            s = s.substring(s.indexOf(Search_text));
            s = s.substring(0, s.indexOf(' '));
            s = s.substring(s.indexOf(DOMAIN_NAME));

            GetUsersSPID("txt_singleUser", s);



        }

        function getDataMultiUSer() {

            var i = 0;
            var j = 0;
            var s = document.getElementById(FieldName_MultiUser).innerHTML;

            var b = 0;

            while (s.indexOf(Search_text) >= 0 ) {

                s = s.substring(s.indexOf(Search_text));
                _multi_user_array[_multi_user_array_Index] = s
                _multi_user_array_Index++;
                s = s.substring(Search_text.length);
               
            }

            for (i = 0; i < _multi_user_array.length; i++) {

                s = _multi_user_array[i]
                s = s.substring(0, s.indexOf(' '));
                s = s.substring(s.indexOf(DOMAIN_NAME));
                document.getElementById("txt_MultiUser").value += s + ",";
                _multi_user_array[i] = s;

                GetUsersSPID("txt_MultiUser", s);
            }

        }
        function GetUsersSPID(textbox_name, username) {

            try {
                $.ajax({
                    url: "_vti_bin/People.asmx",
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/SearchPrincipals");
                    },
                    type: "POST",
                    dataType: "xml",
                    async: false,
                    data: GetUserSearchShop(username),
                    complete: function (xData, status) {
                        $(xData.responseXML).find("PrincipalInfo").each(function () {
                            alert($(this).find("AccountName").text());
                            if (username == $(this).find("AccountName").text()) {
                                var UserInfoID = $(this).find("UserInfoID").text();
                                var DisplayName = $(this).find("DisplayName").text();

                                document.getElementById(textbox_name).value += UserInfoID + ";#" + DisplayName + ";#";


                            }

                        });


                    },


                    contentType: "text/xml; charset=\"utf-8\""
                });

            }
            catch (e) {
                alert(e.message);
            }

        }

        function GetUserSearchShop(username) {
            var soapEnv = "";

            soapEnv += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
            soapEnv += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
            soapEnv += "<soap:Body>";
            soapEnv += "<SearchPrincipals xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">";
            soapEnv += "<searchText>" + username + "</searchText>";
            soapEnv += "<maxResults>100</maxResults>";
            soapEnv += "<principalType>All</principalType>";
            soapEnv += "</SearchPrincipals>";
            soapEnv += "</soap:Body>";
            soapEnv += "</soap:Envelope>";

            return soapEnv;
        }
        </script>
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">

</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >

</asp:Content>

